home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- ### This is needed because for some strange bug only the first two user boot args
- ### are actually exported as env variables
- readRCFile();
- loadBootParm();
-
- $LOG="/tmp/modprobe.log";
- $ERR="/tmp/modprobe.err";
-
- #exit if ! defined $ENV{'REMOTE'};
- ### it's much better to have a default :-)
- $REMOTE = ! defined $ENV{'REMOTE'} ? "hauppauge" : $ENV{'REMOTE'};
-
- readRemotesData();
-
- die "I do not know the remote \"$REMOTE\", your remote won't be started :-(\n"
- unless exists $REMOTE_DEV{$REMOTE};
- install("lircd.conf","/etc",$REMOTE);
- install("lircrc","/root",$REMOTE);
- `ln -s /root/lircrc /root/.lircrc`;
-
- `modprobe -s af_packet >> $LOG 2>> $ERR`;
- `modprobe -s unix >> $LOG 2>> $ERR`;
-
-
- if (@{$REMOTE_MOD{$REMOTE}}[0] eq lirc_serl){
- # print "loading Serial LIRC support\n";
- # `depmod`;
- `mknod /dev/lirc c 61 0`;
- `mknod /dev/lircd c 61 0`;
- `modprobe serial`;
- `setserial /dev/ttyS0 uart none`;
- `modprobe lirc_serial`;
- } else {
- foreach (@{$REMOTE_MOD{$REMOTE}}){
- `modprobe -s $_ >> $LOG 2>> $ERR`
- }
- }
- if( -e "$REMOTE_DEV{$REMOTE}" ){
- `lircd -d $REMOTE_DEV{$REMOTE} -H $REMOTE_DRV{$REMOTE}`;
- } else {
- foreach (@{$REMOTE_MOD{$REMOTE}}){
- `rmmod $_ >> $LOG 2>> $ERR`
- }
- }
-
- ######################################################
-
- sub readRemotesData {
- my @data = split "\n", `find / -name remotes.data`;
- my $confFile=@data[0];
-
- @data = split "\n", `cat "$confFile"`;
- foreach (@data){
- /^(\w+)\s+(\w+)\s+([^\s]+)\s+([^\s]+)\s*$/ or
- die "remotes data file is broken, can't understand line \"$_\"\n";
- $REMOTE_DRV{$1} = $2;
- $REMOTE_DEV{$1} = $3;
- my @tmp = split ",", $4;
- $REMOTE_MOD{$1} = \@tmp;
- }
- }
-
- sub install {
- my $file = shift;
- my $dir = shift;
- my $model = shift;
- `rm -f $dir/$file`;
-
- my @data = split "\n", `find / -name $file.$model`;
- my $confFile=@data[0];
-
- print "$confFile\n";
- if( -e "$confFile" ){
- `cp $confFile $dir/$file`;
- } elsif( $file =~ /^lircrc/ ){
- ### use the hauppauge file if no specific lircrc is available
- $confFile=`find / -name $file.hauppauge`;
- `cp $confFile $dir/$file`;
- } else {
- die "can't find $confFile for: $file.$model :-(\n";
- }
- }
-
- sub loadBootParm {
- foreach (split " ", `cat /proc/cmdline`) {
- next unless /^([^\=]+)\=(.+)$/;
- $ENV{$1} = $2;
- }
- }
-
- sub readRCFile {
- my $bootrc = "/root/.bootrc";
- return unless -e "$bootrc";
- open RC, "$bootrc";
- while(<RC>){
- next if /^\#/ or /^\s*$/;
- next unless /^([^=]+)=(.+)$/;
- $ENV{$1}=$2;
- }
- close RC;
- }
-